package com.compiler.model;

import com.annotation.BindView;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.Name;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;

/**
 * Created by huilin on 2017/6/10.
 */

public class BindViewField {

    private VariableElement variableElement;
    private int rId;

    public BindViewField(Element element) {
        if (element.getKind() != ElementKind.FIELD) {
            throw new IllegalArgumentException("only can filed");
        }
        variableElement = (VariableElement) element;
        BindView annotation = variableElement.getAnnotation(BindView.class);
        rId = annotation.value();
    }

    /**
     * 获取变量名称
     *
     * @return
     */
    public Name getFieldName() {
        return variableElement.getSimpleName();
    }

    /**
     * 获取变量id
     *
     * @return
     */
    public int getrId() {
        return rId;
    }

    /**
     * 获取变量类型
     *
     * @return
     */
    public TypeMirror getFieldTypes() {
        return variableElement.asType();
    }
}
